package com.lsp.test;

import lombok.extern.slf4j.Slf4j;

import java.util.Queue;
@Slf4j
public class Consumer implements Runnable {
    private Queue<String> bags;
    private int maxSize;

    public Consumer(Queue<String> bags, int maxSize) {
        this.bags = bags;
        this.maxSize = maxSize;
    }

    @Override
    public void run() {
        while (true){
            synchronized (bags){
                if(bags.isEmpty()){
                    log.info("bags为空");
                    try {
                        bags.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                String bag = bags.remove();
                log.info("消费者消费："+ bag);
                bags.notify();
            }
        }

    }
}
